/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <iostream>
#include <memory>
#include <string>
#include <fstream>

#include <grpcpp/grpcpp.h>

//#ifdef BAZEL_BUILD
//#include "examples/protos/helloworld.grpc.pb.h"
//#else
//#include "gp.grpc.pb.h"
//#endif

#include "gp.grpc.pb.h"

using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;

using grpc::ClientReader;
using grpc::ClientWriter;

using namespace gp;

//using gp::HelloRequest;
//using gp::HelloReply;
using gp::OpenLid;
using gp::SCanCode;
using gp::XRModule;
using gp::DP8;
using gp::ThermalSeal;
using gp::DP1;
using gp::Module;

using gp::TransTubeParam;

typedef enum
{
  OPENLID_Y = 1,
  OPENLID_Z = 2,
  OPENLID_JAW = 3,
  SCANCODE_ROTATE = 4,

  XRMODULE_Y,
  XRMODULE_Z,
  XRMODULE_JAW,
  XRMODULE_ROTATE,

  DB8_X_,
  DB8_Y_,
  DB8_Z_,

  SUCK_LIQUID,

  THERMAL_SEAL_Z,

  DROPTUBE_JAW,
  DP1_Y_,
  DP1_X_,
  DP1_JawZ_,

  MODULE_OPENLID,
  MODULE_CLOSELID,
  MODULE_XR,
  MODULE_HEAT_SEAL,
  MODULE_DP1_TRANSTUBE,
  
  TRANSFILE_TOPC,
  TRANSFILE_FROMPC,
  MAX_ELE_NUM_ALL
}en_ele_name;

class OpenLidClient {
 public:
  OpenLidClient(std::shared_ptr<Channel> channel)
      : stub_(OpenLid::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response OpenLid_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case OPENLID_Y:
       {
          //printf("open y is called\n");
          status = stub_->OpenLid_Y(&context, movePAram, &reply);
       }
       break;
       case OPENLID_Z:
       {
          //printf("open z is called\n");
          status = stub_->OpenLid_Z(&context, movePAram, &reply);
       }
       break;
       case OPENLID_JAW:
       {
          status = stub_->OpenLid_Jaw(&context, movePAram, &reply);
       }
       break;
       //case: SCANCODE_ROTATE
       //{
       //   status = stub_->OpenLid_Y(&context, movePAram, &reply);
       //}
       //break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<OpenLid::Stub> stub_;
};


class SCanCodeClient {
 public:
  SCanCodeClient(std::shared_ptr<Channel> channel)
      : stub_(SCanCode::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response ScanCode_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case SCANCODE_ROTATE:
       {
         status = stub_->SCanCode_rotate(&context, movePAram, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<SCanCode::Stub> stub_;
};


class XRModuleClient {
 public:
  XRModuleClient(std::shared_ptr<Channel> channel)
      : stub_(XRModule::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response XRModule_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case XRMODULE_ROTATE:
       {
         status = stub_->XRModule_rotate(&context, movePAram, &reply);
       }
       break;
       case XRMODULE_Y:
       {
         status = stub_->XRModule_Y(&context, movePAram, &reply);
       }
       break;
       case XRMODULE_Z:
       {
         status = stub_->XRModule_Z(&context, movePAram, &reply);
       }
       break;
       case XRMODULE_JAW:
       {
         status = stub_->XRModule_Jaw(&context, movePAram, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<XRModule::Stub> stub_;
};

class DP8Client {
 public:
  DP8Client(std::shared_ptr<Channel> channel)
      : stub_(DP8::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response DP8_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case DB8_X_:
       {
         status = stub_->DP8_X(&context, movePAram, &reply);
       }
       break;
       case DB8_Y_:
       {
         status = stub_->DP8_Y(&context, movePAram, &reply);
       }
       break;
       case DB8_Z_:
       {
         status = stub_->DP8_Z(&context, movePAram, &reply);
       }
       break;
       case SUCK_LIQUID:
       {
         status = stub_->DP8_Suck(&context, movePAram, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<DP8::Stub> stub_;
};

class ThermalSealClient {
 public:
  ThermalSealClient(std::shared_ptr<Channel> channel)
      : stub_(ThermalSeal::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response ThermalSeal_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case THERMAL_SEAL_Z:
       {
         status = stub_->ThermalSeal_Z(&context, movePAram, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<ThermalSeal::Stub> stub_;
};

class DP1Client {
 public:
  DP1Client(std::shared_ptr<Channel> channel)
      : stub_(DP1::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response DP1_test(const AxisMoveParam movePAram,int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    switch(eleNumIn)
    {
       case DROPTUBE_JAW:
       {
         status = stub_->Tube_Jaw(&context, movePAram, &reply);
       }
       break;
       case DP1_X_:
       {
         status = stub_->DP1_X(&context, movePAram, &reply);
       }
       break;
       case DP1_Y_:
       {
         status = stub_->DP1_Y(&context, movePAram, &reply);
       }
       break;
       case DP1_JawZ_:
       {
         status = stub_->DP1_JawZ(&context, movePAram, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<DP1::Stub> stub_;
};

class ModuleClient {
 public:
  ModuleClient(std::shared_ptr<Channel> channel)
      : stub_(Module::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response module_test(int eleNumIn) {
    // Data we are sending to the server.
   // AxisMoveParam movePAram;
    //request.set_name(user);

    // Container for the data we expect from the server.
    Response reply;

    // Context for the client. It could be used to convey extra information to
    // the server and/or tweak certain RPC behaviors.
    ClientContext context;
    Status status;
    gp::EmptyRequest fakeParam;
    switch(eleNumIn)
    {
       case MODULE_OPENLID:
       {
         status = stub_->OpenLid(&context, fakeParam, &reply);
       }
       break;
       case MODULE_CLOSELID:
       {
         status = stub_->CloseLid(&context, fakeParam, &reply);
       }
       break;       
       case MODULE_XR:
       {
         status = stub_->XR_AToB(&context, fakeParam, &reply);
       }
       break;
       case MODULE_HEAT_SEAL:
       {
         status = stub_->Heat_Seal(&context, fakeParam, &reply);
       }
       break;
       case MODULE_DP1_TRANSTUBE:
       {
         TransTubeParam transtubeParam;
         transtubeParam.set_srcx(4200);
         transtubeParam.set_srcy(4850);
         transtubeParam.set_srcz(75000);
         transtubeParam.set_tarx(1540);
         transtubeParam.set_tary(2900);
         transtubeParam.set_tarz(62000);
         status = stub_->DP1_TransTube(&context, transtubeParam, &reply);
       }
       break;
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<Module::Stub> stub_;
};

#define _DEBUG_MY 1

#if _DEBUG_MY
const char * fileNames[enConfigFileId::MAX_FILE_INDEX]
{
    "/mnt/nandflash/apps/config/pc/openlid.json",
    "/mnt/nandflash/apps/config/pc/closelid.json",
    "/mnt/nandflash/apps/config/pc/xr.json",
    "/mnt/nandflash/apps/config/pc/bash.json",
    "/mnt/nandflash/apps/config/pc/trans.json",
    "/mnt/nandflash/apps/config/pc/dp8.json",
};
#else
const char * fileNames[enConfigFileId::MAX_FILE_INDEX]
{
    "/mnt/nandflash/apps/config/openlid.json",
    "/mnt/nandflash/apps/config/closelid.json",
    "/mnt/nandflash/apps/config/xr.json",
    "/mnt/nandflash/apps/config/bash.json",
    "/mnt/nandflash/apps/config/trans.json",
    "/mnt/nandflash/apps/config/dp8.json",
};
#endif

#define CHUNK_SIZE 1024

class ConfigFileTransClient {
 public:
  ConfigFileTransClient(std::shared_ptr<Channel> channel)
      : stub_(ConfigFileTrans::NewStub(channel)) {}

  // Assembles the client's payload, sends it and presents the response back
  // from the server.
  Response ConfigFileTrans_test(int eleNumIn, FileTransParam * fileTransParam) {
    // Data we are sending to the server.
    Status status;
    Response reply;
    ClientContext context;    
    
    switch(eleNumIn)
    {
       case TRANSFILE_TOPC:
       {
         //receive from stream
             FileTransParam request;

             std::cout<<"start test trans to pc"<<std::endl;
             FileTransParam recvData;
             std::unique_ptr<ClientReader<FileTransParam> > reader(
             stub_->transToPc(&context, request));

            std::ofstream outfile;
            outfile.open("./tempRecv.txt",std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
            

            while (reader->Read(&recvData)) {

              outfile.write(recvData.chunk().c_str(),recvData.chunk().length());
            }
            Status status = reader->Finish();
            long pos = outfile.tellp();
            outfile.close();
            if(pos == recvData.filesize())
            {
              std::cout<<"file receive success\n"<<std::endl<<"file size:"<<pos<<std::endl;
              rename("./tempRecv.txt", fileNames[fileTransParam->fileid()]);
            }
            
       }
       break;
       case TRANSFILE_FROMPC:
       {
         //send on stream
          Response reply;

          std::cout<<"start test send file from pc to ctl board"<<std::endl;
          std::unique_ptr<ClientWriter<FileTransParam> > writer(
          stub_->transToCtlBorad(&context, &reply));

          std::ifstream infile;
          infile.open(fileNames[fileTransParam->fileid()],std::ofstream::in | std::ofstream::binary);
          
          if(!infile.is_open())
          {
             std::cout<<"open file failed,"<<"file name:"<<fileNames[fileTransParam->fileid()] <<std::endl;
             reply.set_statecode(1);

             return reply;
          }

          char data[CHUNK_SIZE];
          FileTransParam sendData;

          infile.seekg(0,infile.end);
          int fileSize = infile.tellg();

          infile.seekg(0, infile.beg);

          std::cout<<"start sending file,"<<"fileId:"<<fileTransParam->fileid()
          <<"filesize:"<<fileSize<<std::endl;
          
          while (!infile.eof()) {
            
            //infile.read(recvData.chunk().c_str(),recvData.chunk().length());
            infile.read(data,CHUNK_SIZE);
            sendData.set_fileid(fileTransParam->fileid());
            sendData.set_chunk(data,infile.gcount());
            sendData.set_filesize(fileSize);

            writer->Write(sendData);
          }

          std::cout<<"file trans finished\n"<<std::endl;
          writer->WritesDone();
          Status status = writer->Finish();
          long pos = infile.tellg();
          infile.close();
       }
       break;       
       default:
       break;
    }

    // The actual RPC.
    

    // Act upon its status.
    if (status.ok()) {
      //reply.set_statecode(0);
      return reply;
    } else {
      std::cout << status.error_code() << ": " << status.error_message()
                << std::endl;
      reply.set_statecode(1);      
      return reply;
    }
  }

 private:
  std::unique_ptr<ConfigFileTrans::Stub> stub_;
};

int parseFile(const char * fileNameIn,AxisMoveParam * pstMoveParam,int &eleNum);

#define GRPC_TEST_FILE "test_cmd.txt"
#define SYSTEM_SETUP_IP_PORT "10.3.0.201:50051"

int main(int argc, char** argv) {
  // Instantiate the client. It requires a channel, out of which the actual RPCs
  // are created. This channel models a connection to an endpoint (in this case,
  // localhost at port 50051). We indicate that the channel isn't authenticated
  // (use of InsecureChannelCredentials()).
  
  std::string user("world");

  AxisMoveParam moveParam;
  moveParam.set_position(8000);
  moveParam.set_speed(4000);
  moveParam.set_acc(2000);
  moveParam.set_dec(2000);
  int numEle = MAX_ELE_NUM_ALL;
  if(argc>=2)
  {
    parseFile(argv[1],&moveParam,numEle);

    if(numEle>=MAX_ELE_NUM_ALL)
    {
      printf("get move param failed,filename:%s\n",argv[1]);
      parseFile(GRPC_TEST_FILE,&moveParam,numEle);
      if(numEle>=MAX_ELE_NUM_ALL)
      {
        printf("get move param failed,filename:%s\n",GRPC_TEST_FILE);
        return 1;
      }
      
    }
  }
  else
  {
    parseFile(GRPC_TEST_FILE,&moveParam,numEle);
    if(numEle>=MAX_ELE_NUM_ALL)
    {
      printf("get move param failed,filename:%s\n",GRPC_TEST_FILE);
      return 1;
    }
  }

  printf("numEle:%d\n",numEle);
  
  
  Response reply;

  if(OPENLID_JAW>=numEle)
  {
    OpenLidClient openlidClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));
    reply = openlidClient.OpenLid_test(moveParam,numEle);

    std::cout << "openlidClient received: " << reply.statecode() << std::endl;
  }
  else if(numEle==SCANCODE_ROTATE)
  {
    SCanCodeClient scanCodeClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = scanCodeClient.ScanCode_test(moveParam,numEle);

    std::cout << "scanCodeClient received: " << reply.statecode() << std::endl;
  } 
  else if(numEle>=XRMODULE_Y && numEle <= XRMODULE_ROTATE) 
  {
     XRModuleClient xrModuleClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = xrModuleClient.XRModule_test(moveParam,numEle);
  }
  else if(numEle>=DB8_X_ && numEle <= SUCK_LIQUID)
  {
    DP8Client dp8Client(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = dp8Client.DP8_test(moveParam,numEle);
  }
  else if(numEle==THERMAL_SEAL_Z )
  {
    ThermalSealClient thermalSealClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = thermalSealClient.ThermalSeal_test(moveParam,numEle);
  } 
  else if(numEle >= DROPTUBE_JAW && numEle <= DP1_JawZ_)
  {
    DP1Client dp1Client(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = dp1Client.DP1_test(moveParam,numEle);
  }
  else if(numEle >= MODULE_OPENLID && numEle <= MODULE_DP1_TRANSTUBE)
  {
    ModuleClient moduleClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));

    reply = moduleClient.module_test(numEle);
  }
  else if(numEle >= TRANSFILE_TOPC && numEle <= TRANSFILE_FROMPC)
  {
    ConfigFileTransClient transClient(grpc::CreateChannel(
        SYSTEM_SETUP_IP_PORT, grpc::InsecureChannelCredentials()));
    FileTransParam param;
    param.set_fileid(enConfigFileId(moveParam.position()));
    reply = transClient.ConfigFileTrans_test(numEle,&param);
  }

  return 0;
}

int parseFile(const char * fileNameIn,AxisMoveParam * pstMoveParam,int &eleNum)
{
  FILE * fp = fopen(fileNameIn,"r");
  if(fp==NULL)
  {
    eleNum = MAX_ELE_NUM_ALL;
    return 1;
  }

  char StrLine[256];
  char * tmpPtr = NULL;
  while(!feof(fp))
  {
      memset(StrLine,0,256);
      fgets(StrLine,256,fp);
      if(strstr(StrLine,"eleName"))
      {
          tmpPtr = StrLine+8;
          if(strstr(tmpPtr,"openlid_y"))
          {
            eleNum = OPENLID_Y;
            continue;
          }
          else if(strstr(tmpPtr,"openlid_z"))
          {
            eleNum = OPENLID_Z;
            continue;
          }
          else if(strstr(tmpPtr,"openlid_jaw"))
          {
            eleNum = OPENLID_JAW;
            continue;
          }
          else if(strstr(tmpPtr,"scancode"))
          {
            eleNum = SCANCODE_ROTATE;
            continue;
          }
          else if(strstr(tmpPtr,"xr_y"))
          {
            eleNum = XRMODULE_Y;
            continue;
          }
          else if(strstr(tmpPtr,"xr_z"))
          {
            eleNum = XRMODULE_Z;
            continue;
          }
          else if(strstr(tmpPtr,"xr_jaw"))
          {
            eleNum = XRMODULE_JAW;
            continue;
          }
          else if(strstr(tmpPtr,"xr_rotate"))
          {
            eleNum = XRMODULE_ROTATE;
            continue;
          }
          else if(strstr(tmpPtr,"dp8_x"))
          {
            eleNum = DB8_X_;
            continue;
          }
          else if(strstr(tmpPtr,"dp8_y"))
          {
            eleNum = DB8_Y_;
            continue;
          }
          else if(strstr(tmpPtr,"dp8_z"))
          {
            eleNum = DB8_Z_;
            continue;
          }
          else if(strstr(tmpPtr,"thermal"))
          {
            eleNum = THERMAL_SEAL_Z;
            continue;
          }
          else if(strstr(tmpPtr,"suck"))
          {
            eleNum = SUCK_LIQUID;
            continue;
          }
          else if(strstr(tmpPtr,"droptube"))
          {
            eleNum = DROPTUBE_JAW;
            continue;
          }
          else if(strstr(tmpPtr,"moOpenlid"))
          {
            eleNum = MODULE_OPENLID;
            continue;
          }
          else if(strstr(tmpPtr,"moCloselid"))
          {
            eleNum = MODULE_CLOSELID;
            continue;
          }
          else if(strstr(tmpPtr,"moXr"))
          {
            eleNum = MODULE_XR;
            continue;
          }
          else if(strstr(tmpPtr,"filetopc"))
          {
            eleNum = TRANSFILE_TOPC;
            continue;
          }
          else if(strstr(tmpPtr,"filefrompc"))
          {
            eleNum = TRANSFILE_FROMPC;
            continue;
          }
          else if(strstr(tmpPtr,"dp1_x"))
          {
            eleNum = DP1_X_;
            continue;
          }
          else if(strstr(tmpPtr,"dp1_y"))
          {
            eleNum = DP1_Y_;
            continue;
          }
          else if(strstr(tmpPtr,"dp1_x"))
          {
            eleNum = DP1_X_;
            continue;
          }
          else if(strstr(tmpPtr,"dp1_jawZ"))
          {
            eleNum = DP1_JawZ_;
            continue;
          }
          else if(strstr(tmpPtr,"dp1_transtube"))
          {
            eleNum = MODULE_DP1_TRANSTUBE;
            continue;
          }
      }

      if(strstr(StrLine,"pos"))
      {
          tmpPtr = StrLine+4;
          pstMoveParam->set_position(atoi(tmpPtr));
          continue;
      }

      if(strstr(StrLine,"inc"))
      {
          tmpPtr = StrLine+4;
          pstMoveParam->set_acc(strtoul(tmpPtr,NULL,0));
          continue;
      }

      if(strstr(StrLine,"dec"))
      {
          tmpPtr = StrLine+4;
          pstMoveParam->set_dec(atoi(tmpPtr));
          continue;
      }

      if(strstr(StrLine,"speed"))
      {
          tmpPtr = StrLine+6;
          pstMoveParam->set_speed(strtoul(tmpPtr,NULL,0));
          continue;
      }

      if(strstr(StrLine,"fileid"))
      {
          tmpPtr = StrLine+7;
          pstMoveParam->set_position(strtoul(tmpPtr,NULL,0));
          continue;
      }     

  }
  printf("in parseFile, eleNum:%d\n",eleNum);
  fclose(fp);
  return 0;
}



